<!DOCTYPE html>
<html lang="en">

<head>
  <base href="/">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="layui/css/layui.css">
  <style>
    body {
      background: url('https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_1280.jpg') no-repeat;
      background-size: 100% 130%;
    }

    #login_box {
      width: 20%;
      height: 400px;
      background-color: #00000060;
      margin: auto;
      margin-top: 10%;
      text-align: center;
      border-radius: 10px;
      padding: 50px 50px;
    }

    h2 {
      color: #ffffff90;
      margin-top: 5%;
    }

    #input-box {
      margin-top: 5%;
    }

    span {
      color: #fff;
    }

    input {
      border: 0;
      width: 60%;
      font-size: 15px;
      color: #fff;
      background: transparent;
      border-bottom: 2px solid #fff;
      padding: 5px 10px;
      outline: none;
      margin-top: 10px;
    }

    button {
      margin-top: 50px;
      width: 60%;
      height: 30px;
      border-radius: 10px;
      border: 0;
      color: #fff;
      text-align: center;
      line-height: 30px;
      font-size: 15px;
      background-image: linear-gradient(to right, #30cfd0, #330867);
    }

    #sign_up {
      margin-top: 45%;
      margin-left: 60%;
    }

    a {
      color: #b94648;
    }
  </style>
</head>

<body>
<div id="login_box">
  <h2>管理员登录</h2>
  <div id="input_box">
    <input id="account" type="text" placeholder="请输入账户">
  </div>
  <div class="input_box">
    <input id="password" type="password" placeholder="请输入密码">
  </div>
  <button type="button" id="loginbtn">登录</button><br>
</div>
<script src="layui/layui.all.js"></script>
<script>
  const $ = layui.$;
  $('#loginbtn').click(function(){
    let account=$('#account').val();
    let password=$('#password').val();
    let reg=/^[a-zA-Z0-9]{6,16}$/;
    if(account==""){
      layer.msg("账户不能为空！");
      return;
    }else if(password==""){
      layer.msg("密码不能为空！");
      return;
    }else if(reg.test(account)&&reg.test(password)) {
      //登录操作
      $.ajax({
        url: 'sys/dologin',
        data: {account: account, password: password},
        success: function (result) {
          if (result == "success") {
            layer.msg("登录成功！", {icon: 1});
            setTimeout(function () {
              location.href = "sys/index";
            }, 800);
          } else {
            layer.msg("账户不存在或密码错误！");
          }
        },
        error: function () {
          layer.msg("登录失败！")
        }
      });
      return;
    }
  });
</script>
</body>
</html>
